/* 
 * File:   IndexSchema.h
 * Author:
 *
 */

#ifndef INDEXSCHEMA_H
#define	INDEXSCHEMA_H

#include <cstdlib>
#include <set>
#include <pthread.h>
#include "contest_interface.h"
#include "Mutex.h"

class QuadTree;

class IndexSchema {
public:
    IndexSchema(void);
    IndexSchema(const char* _name, uint8_t _attribute_count, KeyType _typ);

    void RegisterHandle(Index* handle);
    void UnregisterHandle(Index* handle);
    void CloseHandles();

    /*To handle the transactions*/
    bool HandleTransaction(Transaction *tx);
    ErrorCode EndTransaction(Transaction *tx);
    ErrorCode executeTransaction(Transaction **tx);
    ErrorCode Rollback(Transaction **tx);

    uint8_t attribute_count() const {
        return dim;
    }

    AttributeType* type() {
        return _type;
    }

    size_t size() {
        return size_;
    }

    QuadTree* get_QuadTree() {
        return qtree;
    }

    const char* name() {
        return this->_name;
    }

    bool is_tx_empty() {
        return transactions_.empty();
    }

    bool is_ix_empty() {
        return handles_.empty();
    }

    bool Compatible(Key key);
    bool Compatible(Record * record);

    Mutex mutex_;

private:
    const char* _name;
    uint8_t dim; // d can be from 1 to 32
    AttributeType* _type;
    size_t size_;
    std::set< Index*> handles_;
    std::set< Transaction*> transactions_;
    QuadTree * qtree;
};

#endif	/* INDEXSCHEMA_H */
